home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / RCS / vm.c,v < prev    next >
Encoding:
Text File  |  1989-06-10  |  9.9 KB  |  434 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mendel:1.7; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     88.09.26.11.22.40;  author nelson;  state Exp;
  11. branches ;
  12. next     1.6;
  13.  
  14. 1.6
  15. date     87.05.27.14.36.27;  author brent;  state Exp;
  16. branches ;
  17. next     1.5;
  18.  
  19. 1.5
  20. date     87.05.11.11.33.22;  author brent;  state Exp;
  21. branches ;
  22. next     1.4;
  23.  
  24. 1.4
  25. date     87.05.08.17.45.57;  author brent;  state Exp;
  26. branches ;
  27. next     1.3;
  28.  
  29. 1.3
  30. date     86.07.24.11.36.24;  author nelson;  state Exp;
  31. branches ;
  32. next     1.2;
  33.  
  34. 1.2
  35. date     86.07.18.11.46.04;  author nelson;  state Exp;
  36. branches ;
  37. next     1.1;
  38.  
  39. 1.1
  40. date     86.07.18.11.43.59;  author nelson;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44.  
  45. desc
  46. @@
  47.  
  48.  
  49. 1.7
  50. log
  51. @Brought up to date.
  52. @
  53. text
  54. @/* vm.c -
  55.  *
  56.  *    This file contains general VM support.
  57.  *
  58.  * Copyright (C) 1985 Regents of the University of California
  59.  * All rights reserved.
  60.  */
  61.  
  62. #ifndef lint
  63. static char rcsid[] = "$Header: vm.c,v 1.6 87/05/27 14:36:27 brent Exp $ SPRITE (Berkeley)";
  64. #endif not lint
  65.  
  66. #include "sprite.h"
  67. #include "vmMach.h"
  68. #include "vmMachInt.h"
  69.  
  70.  
  71. /*
  72.  ----------------------------------------------------------------------
  73.  *
  74.  *  Vm_DevBufferMap --
  75.  *
  76.  *    Map the given range of kernel virtual addresses that are already 
  77.  *    known to be properly mapped at startAddr to mapAddr.
  78.  *    
  79.  * Results:
  80.  *    Pointer into kernel virtual address space of where to access the
  81.  *    memory.
  82.  *
  83.  * Side effects:
  84.  *    The hardware page table is modified.
  85.  *
  86.  *----------------------------------------------------------------------
  87.  */
  88.  
  89. Address
  90. Vm_DevBufferMap(numBytes, startAddr, mapAddr)
  91.     int             numBytes;    /* Number of bytes to map in. */
  92.     register Address startAddr;    /* Kernel virtual address to start mapping in.*/
  93.     register Address mapAddr;    /* Where to map bytes in. */
  94. {
  95.     register Address virtAddr;
  96.     register int     numPages;
  97.     register int     fromPage;
  98.  
  99.     numPages = (((int) startAddr & (VMMACH_PAGE_SIZE_INT - 1)) + numBytes - 1)/
  100.             VMMACH_PAGE_SIZE_INT + 1;
  101.     fromPage = (int) (startAddr) >> VMMACH_PAGE_SHIFT_INT;
  102.     for (virtAddr = mapAddr;
  103.      numPages > 0;
  104.      virtAddr += VMMACH_PAGE_SIZE_INT, numPages--, fromPage++) {
  105.     VmSetPageMap((unsigned int) virtAddr, 
  106.               VmGetPageMap(fromPage << VMMACH_PAGE_SHIFT_INT));
  107.     }
  108.     return(mapAddr + ((int) (startAddr) & VMMACH_OFFSET_MASK_INT));
  109. }
  110.  
  111. /*
  112.  ----------------------------------------------------------------------
  113.  *
  114.  * Vm_MapInDevice --
  115.  *
  116.  *    Map a device at some physical address into kernel virtual address.
  117.  *    This is for use by the controller initialization routines.
  118.  *    This routine looks for a free page in the special range of
  119.  *    kernel virtual that is reserved for this kind of thing and
  120.  *    sets up the page table so that it references the device.
  121.  *
  122.  * Results:
  123.  *    The kernel virtual address needed to reference the device is returned.
  124.  *
  125.  * Side effects:
  126.  *    The hardware page table is modified.  This may steal another
  127.  *    page from kernel virtual space, unless a page can be cleverly re-used.
  128.  *
  129.  *----------------------------------------------------------------------
  130.  */
  131.  
  132. Address
  133. Vm_MapInDevice(devPhysAddr, type)
  134.     Address    devPhysAddr;    /* Physical address of the device to map in */
  135.     int        type;        /* Value for the page table entry type field.
  136.                  * This depends on the address space that
  137.                  * the devices live in, ie. VME D16 or D32 */
  138. {
  139.     register Address         virtAddr;
  140.     register Address        freeVirtAddr = (Address)0;
  141.     register int        page;
  142.     register int        pageFrame;
  143.     VmMachPTE            pte;
  144.     register int        segMap;
  145.  
  146.     /*
  147.      * Get the page frame for the physical device so we can
  148.      * compare it against existing pte's.
  149.      */
  150.     pageFrame = (unsigned)devPhysAddr >> VMMACH_PAGE_SHIFT_INT;
  151.  
  152.     /*
  153.      * Spin through the segments and their pages looking for a free
  154.      * page or a virtual page that is already mapped to the physical page.
  155.      */
  156.     for (virtAddr = (Address)VMMACH_DEV_START_ADDR;
  157.      virtAddr < (Address)VMMACH_DEV_END_ADDR; ) {
  158.     segMap = VmGetSegMap(virtAddr);
  159.     if (segMap == VMMACH_INV_PMEG) {
  160.         /*
  161.          * Make sure there is a valid pmeg for this address.
  162.          */
  163.         virtAddr += VMMACH_SEG_SIZE;
  164.         continue;
  165.     }
  166.     /*
  167.      * Careful, use the corrct page size when incrementing virtAddr.
  168.      * Use the real hardward size (ignore software klustering) because
  169.      * we are at a low level munging page table entries ourselves here.
  170.      */
  171.     for (page = 0 ; page < VMMACH_NUM_PAGES_PER_SEG_INT ;
  172.           page++, virtAddr += VMMACH_PAGE_SIZE_INT) {
  173.         pte = VmGetPageMap(virtAddr);
  174.         if (!(pte & VMMACH_RESIDENT_BIT)) {
  175.             if (freeVirtAddr == 0) {
  176.             /*
  177.              * Note the unused page in this special area of
  178.              * kernel virtual.
  179.              */
  180.             freeVirtAddr = virtAddr;
  181.         }
  182.         } else if ((pte & (VMMACH_TYPE_FIELD | VMMACH_PAGE_FRAME_FIELD))                                 == 0) {
  183.         /*
  184.          * THIS IS BOGUS as we should just unmap everything
  185.          * in the kernel address range reseved for devices
  186.          * and then map everything in by hand.  Right now
  187.          * we are leaving things as the PROM monitor sets them
  188.          * up.  On Sun 2/50's the resident bit is set in this
  189.          * range with the page frame equal to zero.
  190.          */
  191.             if (freeVirtAddr == 0) {
  192.             /*
  193.              * Note the unused page in this special area of
  194.              * kernel virtual.
  195.              */
  196.             freeVirtAddr = virtAddr;
  197.         }
  198.         }
  199. #ifdef notdef
  200.         else if ((pte & VMMACH_PAGE_FRAME_FIELD) == pageFrame &&
  201.                VmMachGetPageType(pte) == type) {
  202.         /*
  203.          * A page is already mapped for this physical address.
  204.          */
  205.         return(virtAddr + ((int)devPhysAddr & VMMACH_OFFSET_MASK));
  206.         }
  207. #endif notdef
  208.     }
  209.     }
  210. #ifdef notdef
  211.     Sys_Printf("Map pf %x => %x\n", pageFrame, freeVirtAddr);
  212. #endif notdef
  213.     if (freeVirtAddr != 0) {
  214.     pte = VMMACH_RESIDENT_BIT | VMMACH_KRW_PROT | pageFrame;
  215. #ifdef SUN3
  216.     pte |= VMMACH_DONT_CACHE_BIT;
  217. #endif SUN3
  218.     VmMachSetPageType(pte, type);
  219.     VmSetPageMap(freeVirtAddr, pte);
  220.     /*
  221.      * Return the kernel virtual address used to access it.
  222.      */
  223.     return(freeVirtAddr + ((int)devPhysAddr & VMMACH_OFFSET_MASK));
  224.     } else {
  225.     return((Address)NIL);
  226.     }
  227. }
  228.  
  229. /*
  230.  * ----------------------------------------------------------------------------
  231.  *
  232.  * Vm_GetDevicePage --
  233.  *
  234.  *      Allocate and validate a page at the given virtual address.  It is
  235.  *    assumed that this page does not fall into the range of virtual 
  236.  *    addresses used to allocate kernel code and data and that there is
  237.  *    already a PMEG allocate for it.
  238.  *
  239.  * Results:
  240.  *      None.
  241.  *
  242.  * Side effects:
  243.  *      The hardware segment table for the kernel is modified to validate the
  244.  *    the page.
  245.  *
  246.  * ----------------------------------------------------------------------------
  247.  */
  248. /*ARGSUSED*/
  249. #ifdef notdef
  250. void
  251. Vm_GetDevicePage(virtAddr) 
  252.     int    virtAddr;    /* Virtual address where a page has to be validated
  253.                at. */
  254. {
  255.     return;
  256. }
  257. #endif
  258.  
  259. @
  260.  
  261.  
  262. 1.6
  263. log
  264. @cosmetic junk.
  265. @
  266. text
  267. @d10 1
  268. a10 1
  269. static char rcsid[] = "$Header: vm.c,v 1.5 87/05/11 11:33:22 brent Exp $ SPRITE (Berkeley)";
  270. a15 1
  271. #include "vmSunConst.h"
  272. d23 2
  273. a24 3
  274.  *    Map the given range of kernel virtual addresses into the kernel's
  275.  *    VAS starting at the given kernel virtual address.  It is assume
  276.  *    that there are already PMEGS allocated for these pages.
  277. d46 3
  278. a48 3
  279.     numPages = (((int) startAddr & (VM_PAGE_SIZE_INT - 1)) + numBytes - 1) / 
  280.             VM_PAGE_SIZE_INT + 1;
  281.     fromPage = (int) (startAddr) >> VM_PAGE_SHIFT_INT;
  282. d51 1
  283. a51 1
  284.      virtAddr += VM_PAGE_SIZE_INT, numPages--, fromPage++) {
  285. d53 1
  286. a53 1
  287.               VmGetPageMap(fromPage << VM_PAGE_SHIFT_INT));
  288. d55 1
  289. a55 1
  290.     return(mapAddr + ((int) (startAddr) & VM_OFFSET_MASK_INT));
  291. d89 2
  292. a90 1
  293.     Vm_PTE            pte;
  294. a91 1
  295.     register int        pageFrame;
  296. d97 1
  297. a97 1
  298.     pageFrame = (unsigned)devPhysAddr >> VM_PAGE_SHIFT_INT;
  299. d103 2
  300. a104 2
  301.     for ((int)virtAddr = VM_DEV_START_ADDR;
  302.      (int)virtAddr < VM_DEV_END_ADDR; ) {
  303. d106 1
  304. a106 1
  305.     if (segMap == VM_INV_PMEG) {
  306. d110 1
  307. a110 1
  308.         virtAddr += VM_SEG_SIZE;
  309. d118 4
  310. a121 4
  311.     for (page = 0 ; page < VM_NUM_PAGES_PER_SEG ;
  312.           page++, virtAddr += VM_PAGE_SIZE_INT) {
  313.         VM_PTE_TO_INT(pte) = VmGetPageMap(virtAddr);
  314.         if (pte.resident == 0) {
  315. d129 1
  316. a129 1
  317.         } else if (pte.type == 0 && pte.pfNum == 0) {
  318. d147 2
  319. a148 2
  320.         else if (pte.pfNum == pageFrame &&
  321.                pte.type == type) {
  322. d152 1
  323. a152 1
  324.         return(virtAddr + ((int)devPhysAddr & VM_OFFSET_MASK));
  325. d161 1
  326. a161 3
  327.     pte = vm_ZeroPTE;
  328.     pte.resident = 1;
  329.     pte.protection = VM_KRW_PROT;
  330. d163 1
  331. a163 1
  332.     pte.dontCache = 1;
  333. d165 1
  334. a165 2
  335.     pte.pfNum = pageFrame;
  336.     pte.type = type;
  337. d170 1
  338. a170 1
  339.     return(freeVirtAddr + ((int)devPhysAddr & VM_OFFSET_MASK));
  340. @
  341.  
  342.  
  343. 1.5
  344. log
  345. @Added Vm_MapInDevice and trimmed it down
  346. @
  347. text
  348. @d10 1
  349. a10 1
  350. static char rcsid[] = "$Header: vm.c,v 1.4 87/05/08 17:45:57 brent Exp $ SPRITE (Berkeley)";
  351. d159 3
  352. d180 30
  353. @
  354.  
  355.  
  356. 1.4
  357. log
  358. @Added Vm_MapInDevice (but its so big!)
  359. @
  360. text
  361. @d10 1
  362. a10 1
  363. static char rcsid[] = "$Header: vm.c,v 1.3 86/07/24 11:36:24 nelson Exp $ SPRITE (Berkeley)";
  364. d48 3
  365. a50 3
  366.     numPages = (((int) startAddr & (VM_PAGE_SIZE - 1)) + numBytes - 1) / 
  367.             VM_PAGE_SIZE + 1;
  368.     fromPage = (int) (startAddr) >> VM_PAGE_SHIFT;
  369. d53 1
  370. a53 1
  371.      virtAddr += VM_PAGE_SIZE, numPages--, fromPage++) {
  372. d55 1
  373. a55 1
  374.               VmGetPageMap(fromPage << VM_PAGE_SHIFT));
  375. d57 1
  376. a57 1
  377.     return(mapAddr + ((int) (startAddr) & VM_OFFSET_MASK));
  378. a90 1
  379.     register int        pageFrame;
  380. d93 1
  381. d147 3
  382. a149 1
  383.         } else if (pte.pfNum == pageFrame &&
  384. d156 1
  385. @
  386.  
  387.  
  388. 1.3
  389. log
  390. @Fixed call to VmGetPageMap
  391. @
  392. text
  393. @d10 1
  394. a10 1
  395. static char rcsid[] = "$Header: vm.c,v 1.2 86/07/18 11:46:04 nelson Exp $ SPRITE (Berkeley)";
  396. d14 2
  397. d59 116
  398. @
  399.  
  400.  
  401. 1.2
  402. log
  403. @Put things in registers.
  404. @
  405. text
  406. @d10 1
  407. a10 1
  408. static char rcsid[] = "$Header: vm.c,v 1.1 86/07/18 11:43:59 nelson Exp $ SPRITE (Berkeley)";
  409. d52 2
  410. a53 1
  411.     VmSetPageMap((unsigned int) virtAddr, VmGetPageMap(fromPage));
  412. @
  413.  
  414.  
  415. 1.1
  416. log
  417. @Initial revision
  418. @
  419. text
  420. @d10 1
  421. a10 1
  422. static char rcsid[] = "$Header: bootVm.c,v 1.1 86/07/16 17:12:02 brent Exp $ SPRITE (Berkeley)";
  423. d38 3
  424. a40 3
  425.     int        numBytes;    /* Number of bytes to map in. */
  426.     Address    startAddr;    /* Kernel virtual address to start mapping in.*/
  427.     Address    mapAddr;    /* Where to map bytes in. */
  428. d42 3
  429. a44 3
  430.     Address         virtAddr;
  431.     int            numPages;
  432.     int            fromPage;
  433. @
  434.